/////////////////////////////////////////////////////////////////////////////
//
// Readme for Diplomod script AI for CTP2 - Version 3.6 (Beta)
//
// Diplomacy by Dale
//
// 28-June-2001
//
// Free for public use and modification
//
/////////////////////////////////////////////////////////////////////////////

Design:
-------

The overall design of Diplomod is simple.  In point form it flows like this:

1. At the beginning of the game it will display a welcome msg, initialise the AI's diplomacy settings and set game variables to zero if required.
2. Each turn there is a regard cheat to make AI's not at war and of the same govt like each other more.  CANCELLED!!!
3. In the main routine which is processed every turn for every civ, the turn marker is increased on player 1's turn (not everyone plays with barbarians you know).
4. An AI civ will consider 16 diplomatic proposals for each other civ.  Also, it will consider if it should change diplomatic stance with each civ.
5. After processing all the proposal considerations, it will analyse whether to create an embassy with each civ.
6. Also considered each turn is the withdraw script.
7. Withdraw will check if there is a withdraw troops agreement (agreement ID 3).
8. The script will check each unit's location.  If in a square under a agreement, it looks at the terrain.  If the terrain is land it will randomly pick a square adjacent but outside of that civ's borders and put the unit there.

That's all there is to it.

Reasoning:
----------

I have included the regard cheat for same govt AI's since throughout history we have seen ideologies stick together.  Capitalists v Communists.  Democracy v Fascism.  Etc.  CANCELLED!!!!!!!!!!

The 16 proposals I have chosen are the ones that I think would be beneficial to an AI civ, or to AI-AI relations.  I set out to improve AI-AI relations, so this was my major goal.  To make the AI consider proposals that will promote those relations and I feel that I have done a good job at simulating this.  There are a number of proposals that I have not included, because I feel that an AI should not persue them.  For example, I have not included the OFFER_CITY proposal because I don't believe an AI should give up any of its cities.  It has enough trouble keeping them without this added situation.

Since the AI is almost totally incapable of creating embassies with anyone, I wrote the art of establishing embassies to conquor this.  Yes, I know it is forced, and maybe the AI didn't want an embassy with a certain civ, but it works so shutup!  :)  I'm sure there has to be a better way, but I was more interested in the actual embassy creation, not the way it does it.  First, it checks if it has the required advance (ADVANCE_BUREAUCRACY) and then finds the civ's capital and creates an embassy there.  It does this by creating a diplomat who then carries out the create embassy order and is finally disbanded.  For some wierd reason, using a diplomat is the only way I could find to create an embassy in a city.

The changes I made to the diplomacy.txt file can simply be stated as NECESSARY!  The default values as given by Activision were so out of whack that I was surprised after understanding this file, that the AI could actually do ANY diplomacy.  So I set out to balance this file as best I could.  I increased the priorities on favourable requests/offers and balanced out AI's response priorites.  To a Human, the AI will be more demanding and agressive than it was by default.  To another AI, it will be friendly or equal.  I lowered priorites on unfavourable responses (like accepting some things) and even made zero some others.  Now, gone are the proposals straight after it rejects the same thing, the imbalanced way you could use diplomacy against the AI and all importantly it now appears like there is an intelligent being doing diplomacy with you instead of a programmed AI that is totally stupid.

In V3.4 I re-disabled the request/offer break agreements.  Quite simply, some players were experiencing bugs with these proposals.  I could not recreate them here, so was forced to elliminate the bugs in the only way I could, by re-disabling the proposals.

I disabled the research pact option for the simple fact that the Activision bug within this agreement (where the AI gets an advance every turn and you don't get any benefits) cannot and will not be fixed.

I divided an AI's diplomatic stance settings into 6 seperate classes: Warmonger, Suckup and Normal for both AI and Human.  I seperated the Human settings into its own set because the AI could not do proper diplomacy with another AI on the Human settings.  Because of the way the AI plays, some settings needed extra balancing (some even elliminated) when dealing with another AI.  Without this seperation the AI to AI diplomacy was never going to be any good.

Next we get to withdraw.  This is the one section that has given me the most grief in the building of this mod.  For months, complaints were expressed about how the AI will make a withdraw troops agreement and then not follow through with it.  I also was disgusted with it, but saw it as part of the design of the game.  I mean, not every civ in history has left a location after agreeing to.  I saw it more as a beligerent leader than a bug.  But I relented and as part of the coding for Diplomod I coded the withdraw script.  Now there were a lot of bugs in the first release.  I apologise for that, I hadn't fully tested it.  But now we're at V1.3, and I have covered as many conditions as I can think of.  Of course, we may find more problems.

Why withdraw does what it does is because of my way of seeing the world.  All through history, the seas have been a very hard place to patrol and keep control of.  Land on the other hand is a lot easier to keep an eye on.  By using border patrols and garrisons, cities strategically placed in chokepoints, nations have been able to keep control of their land.  But the seas constantly change.  It's a big place out there (70% of our planet is water!).  This is why withdraw will ONLY expel units that are on a land terrain.  Anything on a sea terrain square (including planes in flight, units on transports, etc) will be ignored for this simple reason.  Also, I saw a situation in V1.1 where the AI was trying to move a battleship through a straight between two islands I controlled, and everytime the battleship hit my border it got expelled.  The AI was too stupid to move the battleship around my islands, but for 30 turns kept moving into my border.  It will now be allowed to move that ship through my straight to the open seas on the other side.  This also allows for pirates to get in and cause you troubles (like English and Portugese pirates kept hassling the Spanish Main).

When the script actually expels the unit, it will check its veteran status and flag yes or no.  It will then disband that unit, and create another unit of the same type in the new location, giving it back its veteran status if it had one.  Yes, I know hitpoints will be healed, but stiff.  Accept that as a consequence of the AI actually withdrawing.  ;)  Hey, it benefits the AI, and all the help it gets is good right?

Things to look for if you mod this in:
--------------------------------------

If you want to add Diplomod to your own mod, I just want to point out a couple of things to help you implement it cleanly.  This mod is setup for the default CTP2 install.

- If you use a different advance than Bureaucracy to allow diplomats, or have a unit that can create embassies before diplomats, you should change the advance flag within the embassy creation check to the advance you used.  Here is the line:
     if(HasAdvance(player[0], ID_ADVANCE_BUREAUCRACY) && !(IsHumanPlayer(player[0]))) {
And also the line that creates the diplomat who is going to establish the embassy to the unit you have used.

- If you want to change the priority that an AI will consider all new proposals at, I have defined this in one variable, DIP_requestpriority.  To change the priority use the following line:
     DIP_requestpriority = 1500;

- If you believe that an AI is swapping its maps to frequently for the first 500 turns, you can slow it down (or speed it up) by using the following section of code:
     if(DIP_turns <= 500) {
          DIP_tmpvalue = 600 - DIP_turns;
     } else {
          DIP_tmpvalue = 100;
     }
The first line defines how many turns to slow down the process for.  I've used 500 turns.  The forth line defines the chance of swapping maps after the above amount of turns has been processed, in terms of 1 in ......  I've used 100 (1 in 100, or 1%).  The second line defines the increasing chance formula I used.  Basically, the Ai starts out with a 1 in 600 chance of swapping its maps on turn zero.  On turn 100 it's 1 in (600 - 100) chance.  And so on until turn 500 when it's 1 in (600 - 500) or 1 in 100 which is the default value of 1% I've used for the rest of the game.

End:
----

Have fun with this.  Remember, this is free for you to use, just keep my headers and mention me in the credits.  If you're someone from Activision (or the CTP1/2 team), let me know by email what you think of it.  Hey, I want to be a games programmer so I gotta get my name out there somehow.  :D  Thanks for your support.

Dale

dale.kent@alphawest6.com.au
